package cn.njp.learn.basic.io;

import java.io.File;
import java.io.IOException;

import org.junit.Test;

public class FilePermissionExample {
	@Test
	public void testFilePermission(){
		try {
			String workDir = System.getProperty("user.dir");
			String filePath = workDir + File.separator + "echo.bat";
			File file = new File(filePath);
			
			if(file.exists()){
				System.out.println("Is executable : " + file.canExecute());
				System.out.println("Is writable : " + file.canWrite());
				System.out.println("Is readable : " + file.canRead());
			}
			
			file.setExecutable(false);
			file.setReadable(false);
			file.setWritable(false);
			
			if(file.exists()){
				System.out.println("Is executable : " + file.canExecute());
				System.out.println("Is writable : " + file.canWrite());
				System.out.println("Is readable : " + file.canRead());
			}
			
			
				if(file.createNewFile()){
					System.out.println("file create ok...");
				}else{
					System.out.println("file create failed...");
				}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		
	}
}
